<?php
/**
 * 管理员后台控制器
 * 
 * @version $Id: User.php 283 2012-04-28 14:41:52Z linsir123 $
 */
class controllerUser extends AdminController 
{
	/**
	 * 用户列表
	 */
	public function actionIndex()
	{
		$show = 15;
		
		///
		$descs = array('desc'=>'降序', 'asc'=>'升序');
		$orders = array(
			'create_time'=>'注册时间', 
			'login_time'=>'最近登录时间',
			'login_times'=>'登录次数',
			'balance'=>'帐户余额',
		);
		
		///
		$params = array();
		if (isset($_POST['order']) && isset($_POST['desc'])) {
			$order = intval($_POST['order']);
			$desc = intval($_POST['desc']);
			$orderKeys = array_keys($orders);
			$descKeys = array_keys($descs);
			if (isset($orderKeys[$order]) && isset($descKeys[$desc])) 
				$params['order'] = array($orderKeys[$order], $descKeys[$desc]);
		}
		if (isset($_POST['uid'])) 
			$params['uid'] = intval($_POST['uid']);
		if (isset($_POST['state']) && $_POST['state'] != '-1') 
			$params['state'] = intval($_POST['state']);
		if (isset($_POST['type']) && $_POST['type'] != '-1') 
			$params['type'] = trim($_POST['type']);
			
		///
		$ma = MA::user();
		if ($count = $ma->getListCount($params)) {
			$page = $this->pagination($show, $count, 'user/index');
			$list = $ma->getList(($page-1)*$show, $show, $params);
			View::assign('list', $list);
		}
		
		$tmp = array(-1=>'请选择...');
		
		///
		View::display('user/user_list');
		View::assignSet(array(
			'title' => '用户列表',
			'orders' => array_values($orders),
			'descs' => array_values($descs),
			'states' => ($tmp+$ma->states),
			'types' => ($tmp+$ma->types)
		));
	}
	
	/**
	 * 登录某个用户
	 */
	public function actionLogin()
	{
		$ma = MA::user();
		$uId = intval($_GET['id']);
		$user = $ma->getById($uId);
		if ($user['type'] != '0') {
			$tmp = $ma->getProfileByUid($uId);
			$user['username'] = $tmp['nick'];
		}
		if ( ! empty($user)) {
			$ma->setLoginSession($user);
			lpUrl::_r('user/main');
		} else 
			echo '找不到该用户';
	}
}
